package cn.supermarket.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import java.io.Serializable;



@Configuration
public class RedisConfiguration {
    /**
     * redis数据库配置类
     * @return <K , V>
     */

    @Bean
    public RedisTemplate<String, Serializable> redisTemplate(RedisConnectionFactory factory) {
        RedisTemplate<String, Serializable> template = new RedisTemplate<>();
        /*序列化器*/
        template.setConnectionFactory(factory);                    //连接工厂
        template.setKeySerializer(RedisSerializer.string());       //key序列化器
        template.setValueSerializer(RedisSerializer.json());       //value序列化器
        return template;
    }
}
